/**
 * Copyright phonemap.com
 *
 * Licensed under the phonemap.com License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.phonemap.com/licenses/LICENSE-1.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
'use strict';

/**
 * After Login.
 */
function afterLogin() {
	initialize();
}

//Get avatar path
var getAvatar = function(user) {
	return 'http://graph.facebook.com/'+user.user_id+'/picture';
}; 

var initialize = function() {
	//load user account from cookie
	var useraccount = $.cookie('useraccount');
	if (useraccount != '' && useraccount != null) {
		$.ajax({
			url : "/search?action=initMap&userId="+useraccount,
			type: 'GET',
	        data: '',
			success : function(resp) {
				if (resp != null) {
					// getting the data from the response object
					var data = resp.data;
					//initialize map
					if(data.length > 0) {
						PhonemapUtil.setProfile(data[0]);
					}
				}
			},
			error : function(resp){
				alert('Cannot get data! Please check again');
			}
		});
	} else {//not login
		//Go to index page
		document.location.href = '/index.html';
	}
};